/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package util;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.net.URL;
import javax.swing.JDesktopPane;
import javax.swing.JOptionPane;

/**
 *
 * @author lg
 */
public class backGround extends JDesktopPane {    
    
        private Image img;      

    public backGround() {
        try {
            URL im = getClass().getResource("fundo.jpg");
            System.out.println(im.toString());
            img = Toolkit.getDefaultToolkit().getImage(im);
            //img = javax.imageio.ImageIO.read((getClass().getResourceAsStream("/view/GUI/fundo")));       
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
    
        @Override    
        public void paintComponent(Graphics g) {    
            super.paintComponent(g);    
            if (img != null) {    
                Dimension dimension = this.getSize();    
                int x = (int)(dimension.getWidth() - img.getWidth(this)) / 2;    
                int y = (int)(dimension.getHeight() - img.getHeight(this)) / 2;    
    
                g.drawImage(img, x, y, img.getWidth(this), img.getHeight(this), this);    
            } else {    
                g.drawString("Imagem nao encontrada", 50, 50);    
            }    
        }    
    }